package org.thinkinbunny.financial.activity;



import org.thinkinbunny.financial.util.Log;
import org.thinkinbunny.financial.util.ShowTools;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;

public class MyActivity extends Activity implements OnClickListener{
	public static String musername;
	private Handler handler;
	private Thread mUiThread;

	public Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				ShowTools.toast((String) (msg.obj));
				break;
			}
		}
	};
	
	@Override
	protected void onCreate(android.os.Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mUiThread = Thread.currentThread();
		handler = new Handler();
	}
	;
	/**
	 * 统一 post 接口
	 */
	public void post(final Runnable action) {
		Log.i("post", "handler==="+handler);
		handler.post(new Runnable() {
			@Override
			public void run() {
				if (MyActivity.this.isFinishing()) {
					return;
				}
				action.run();
			}
		});
	}

	/**
	 * 统一 post 接口
	 */
	public void post(final Runnable action, int delayMillis) {
		handler.postDelayed(new Runnable() {
			@Override
			public void run() {
				if (MyActivity.this.isFinishing()) {
					return;
				}
				action.run();
			}
		}, delayMillis);
	}

	/**
	 * 如果正在UI线程则马上执行，否则就加入到任务队列
	 */
	public void attemptRunOnUiThread(final Runnable action) {
		if (Thread.currentThread() != getUiThread()) {// 判断UI线程
			post(action);
		} else {
			action.run();
		}
	}
	private Thread getUiThread() {
		return mUiThread;
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}	  
}
